package com.test.customerweb.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.test.customerweb.dto.CartDto;

@Controller
@Scope("session")
public class CartController {
	@Autowired 
	CartDto cartDatal;
	public CartDto getCartDatal() {
		return cartDatal;
	}

	public void setCartDatal(CartDto cartDatal) {
		this.cartDatal = cartDatal;
	}

	@RequestMapping("/home")
	public ModelAndView home(){
		return new ModelAndView("index");
	}
	@RequestMapping("/serch")
	public ModelAndView search()
	{
		List medicines=new ArrayList();

		for(int i=10; i<=24; i++)
		{
			medicines.add("medicine"+i);
			//			medicines.add("m1");
		}
		return new ModelAndView("search","medicines", medicines);
	}
	@RequestMapping("addtocart")
	public ModelAndView addtoCart(@RequestParam("mid") String medicineID)
	{
		cartDatal.setMedicineID(medicineID);
		cartDatal.setMedicineName("name");
		cartDatal.setPrice("100.00");
		cartDatal.setQuatity("2");
		cartDatal.setCustID("cid");
		return new ModelAndView("addedcart");
	}
}
